import '../net_code.dart';
import '../net_exception.dart';

class AppResponse<T> {
  int _code = 0;

  int get code => _code;

  T? _data;

  T? get data => _data;

  String _msg = "";

  String get msg => _msg;

  bool _status = true;

  bool get status => _status;

  bool get ok => _code == NetCode.NET_CODE_OK;

  AppResponse.ok(T? data, {int? code, msg = "", status = true}) {
    this._data = data;
    this._code = code ?? NetCode.NET_CODE_OK;
    this._msg = msg;
    this._status = status;
  }

  AppResponse.exception(NetException e) {
    this._code = e.code;
    this._msg = e.message;
    this._status = false;
  }

  Map<String, dynamic> toJson() =>
      {'code': code, 'data': data, 'msg': msg, 'status': status};
}
